﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsImageResizer
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        private void OpenExistingFile()
        {
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string fileName = openFileDialog.FileName;

            ImageForm imageForm = new ImageForm();
            try
            {
                imageForm.LoadFile(fileName);
                imageForm.MdiParent = this;
                imageForm.Show();
                SetInfoStatusBar("Loaded file: " + fileName);
            }
            catch (IOException)
            {
                imageForm.Dispose();
                MessageBox.Show("Can not load file: " + fileName, "Error");
            }
        }

        private void SaveCurrentFile()
        {
            ImageForm activeImageForm = (ImageForm)this.ActiveMdiChild;
            if (activeImageForm != null)
            {
                activeImageForm.Save();
            }
        }

        public void SetInfoStatusBar(string text)
        {
            informationStatusStrip.Text = text;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            SetInfoStatusBar("Application started.");
        }

        private void SaveClick(object sender, EventArgs e)
        {
            this.SaveCurrentFile();
        }

        private void ExitClick(object sender, EventArgs e)
        {
            this.Close();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            this.OpenExistingFile();
        }

        //public void SetLineStatusBar(string text)
        //{
        //    linesToolStripStatusLabel.Text = text;
        //}
    }
}
